package com.yaoweigroup.community.adapter;

import java.util.List;

import com.yaoweigroup.community.R;
import com.yaoweigroup.community.enity.News;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NewsAdapter extends BaseAdapter {

	private Context context;
	private List<News> list;
	private LayoutInflater mInflater;

	public NewsAdapter(Context context, List<News> list) {
		mInflater = LayoutInflater.from(context);
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		if (convertView == null) {
			holder = new Holder();
			convertView = mInflater.inflate(R.layout.adapter_news_item, null);
			convertView.setTag(holder);
			holder.icon_iv = (ImageView) convertView.findViewById(R.id.icon_iv);
			holder.name_tv = (TextView) convertView.findViewById(R.id.name_tv);
		} else {
			holder = (Holder) convertView.getTag();
		}

		News news = list.get(position);
		holder.name_tv.setText(position + 1 + ".  " + news.getNewtitle() + "["
				+ news.getTypename() + "]");
		return convertView;
	}

	public final class Holder {

		TextView name_tv;
		ImageView icon_iv;
	}

	public void setDataChange(List<News> list) {
		this.list = list;
		notifyDataSetChanged();
	}

}
